<template>
  <view>
    <view class="addressBox">
      <view class="addInfoBox" v-if="JSON.stringify(address)==='{}'">
        <button @click="changeAddress" type="primary" size="mini" class="addDot">请选择收获地址+</button>
      </view>
      <view class="addressInfo" v-else @click="changeAddress">
        <view class="row1">
          <view class="row1-left">
            收货人：{{address.userName}}
          </view>
          <view class="row1-right">
            <text> 电话: {{address.telNumber}}</text>
            <uni-icons type="forward" size="16"></uni-icons>
          </view>
        </view>
        <view class="row2">
          <view class="row2-left">
            收获地址：
          </view>
          <view class="row2-right">
            {{addressInfo}}
          </view>
        </view>
      </view>
    </view>
    <image class="addressBorder" src="../../static/cart_border@2x.png" mode=""></image>
  </view>
</template>

<script>
import {
  mapGetters,mapState,mapMutations
} from 'vuex'
  export default {
    name: "my-address",
    data() {
      return {
        // address: {
        //   // name:'666'
        // }
      };
    },
    computed: {
    ...mapState('m_user',['address']),
    ...mapGetters('m_user',['addressInfo'])
    // 地址数据
      // addstr() {
      //   if(!this.address.provinceName) return '';
      //   return this.address.provinceName + this.address.cityName + this.address.countyName + this.address.detailInfo
      // }
    },
    methods: {
      ...mapMutations('m_user',['updateAddress']),
      async changeAddress() {
        // uniapp获取收货地址
        const data = await uni.chooseAddress().catch(err => err)
        if (data[0] === null && data[1].errMsg === "chooseAddress:ok") {
          console.log(data[1]);
          // this.address = data[1]
          this.updateAddress(data[1])
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  .addInfoBox {
    height: 90px;
    -webkit-box-sizing: border-box;
    padding: 5px 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .addressBorder {
    display: block;
    height: 5px;
    width: 100%;
  }

  .addressInfo {
    font-size: 12px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;

    .row1 {
      display: flex;
      justify-content: space-between;

      .row2-right {
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .row2 {
      display: flex;
      align-items: center;
      margin-top: 10px;
    }

    .row2-left {
      white-space: nowrap;
    }
  }
</style>
